package com.example.springbott.wx_controller;

import com.example.springbott.bean.BaseRespVo;

import com.example.springbott.bean.MarketUser;
import com.example.springbott.wx_service.WxGoodsService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.springbott.bean.common.BasePageInfo;
import com.example.springbott.bean.common.CommonData;
import com.example.springbott.bean.kerbal.CategoryListVo;
import com.example.springbott.bean.kerbal.GoodsDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("wx/goods")

public class WxGoodsController {
    @Autowired
    WxGoodsService wxGoodsService;

    @RequestMapping("count")
    public BaseRespVo wxHomeCount() {
        return BaseRespVo.ok(wxGoodsService.wxHomeCount());
    }

    @RequestMapping("category")
    public BaseRespVo wxGoodsCategory(Integer id) {
        return BaseRespVo.ok(wxGoodsService.wxGoodsCategory(id));
    }


    @RequestMapping("list")
    public  BaseRespVo wxGoodsList(BasePageInfo basePageInfo,Integer categoryId,String keyword,Integer brandId){

        return BaseRespVo.ok( wxGoodsService.WxGoodsList(basePageInfo, categoryId,keyword,brandId));

    }


    @RequestMapping("detail")
    public  BaseRespVo wxGoodsDetail(Integer id,HttpServletRequest request){
        // 留下足迹footprint
        MarketUser user = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        if (user.getId() != null){
            wxGoodsService.wxGoodsDetailFootprint(id); // 不要删除这条记录
        }

        GoodsDetailVo goodsDetailVo = wxGoodsService.wxGoodsDetail(id);

        return BaseRespVo.ok(goodsDetailVo);
    }

    /**
     * 天气相关商品
     *http://localhost:8083/wx/goods/related?id=1009024
     * @param id id
     * @return {@link BaseRespVo}
     * @kerbal
     */
    @RequestMapping("related")
    public BaseRespVo wxGoodsRelated(Integer id){
        CommonData commonData = wxGoodsService.wxGoodsRelated(id);
       return BaseRespVo.ok(commonData);

    }



}
